﻿using NetBrick.Client;
using NetBrick.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityExample.Common;


class UnityExampleClient : Client
{
    public static UnityExampleClient Instance { get; set; }

    public Guid Id;

    public List<Guid> Players = new List<Guid>();

    public UnityExampleClient() : base("UnityExample")
    {
        Instance = this;
    }

    public override void DebugError(string message, params object[] arg)
    {
        Debug.LogErrorFormat(message, arg);
    }

    public override void DebugInfo(string message, params object[] arg)
    {
        Debug.LogFormat(message, arg);
    }

    public override void DebugSevere(string message, params object[] arg)
    {
        Debug.LogErrorFormat(message, arg);
    }

    public override void DebugWarn(string message, params object[] arg)
    {
        Debug.LogWarningFormat(message, arg);
    }

    protected override void Init()
    {
        // Register packet types
        Packet.Instance.Register((ushort)UnityExamplePacketCode.UpdateList, typeof(UpdatePacket.PlayerList));
        Packet.Instance.Register((ushort)UnityExamplePacketCode.UpdateEvent, typeof(UpdatePacket.Event));
        Packet.Instance.Register((ushort)UnityExamplePacketCode.UpdateRequest, typeof(UpdatePacket.Request));
        Packet.Instance.Register((ushort)UnityExamplePacketCode.Welcome, typeof(WelcomePacket));

        AddPacketHandler((ushort)UnityExamplePacketCode.UpdateList, new UpdateListHandler());
        AddPacketHandler((ushort)UnityExamplePacketCode.Welcome, new WelcomeHandler());
        AddPacketHandler((ushort)UnityExamplePacketCode.UpdateEvent, new UpdateHandler());

        Connect("localhost", 50000);
    }

    protected override void OnConnect()
    {
        DebugInfo("Connected");
    }

    protected override void OnDisconnect(string reason)
    {
        DebugInfo("Disconnected: {0}", reason);
    }
}
